package lx2;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
//客户端：发送一条数据，接收服务端反馈的消息并打印
//服务器：接收数据并打印，再给客户端反馈消息
public class Client {
    public static void main(String[] args) throws IOException {
        //创建客服端对象
        Socket s = new Socket("127.0.0.1", 1000);
        //2.可以从连接通道获取输出流
        OutputStream os = s.getOutputStream();
        os.write("hello".getBytes());

        //写出一个结束标记 相当于结束了输出流
        s.shutdownOutput();

        //3.接收服务端反馈的消息
        InputStream is = s.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        int b;
        while ((b = isr.read()) != -1){
            System.out.print((char)b);
        }
        //3.关闭资源
        s.close();
    }
}
